package com.cloud.base.consumer;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.cloud.api.mq.AlarmMsg;
import com.cloud.api.mq.CglxMsg;
import com.cloud.base.service.ISmsService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.function.Consumer;

@Slf4j
@Component
public class AlarmSmsConsumer {
    @Resource
    private ISmsService mySmsService;

     @Bean
    Consumer<AlarmMsg> alarmSms() {
        log.info("订阅成功");
        return msg -> {
            log.info("发送短信成功 => vin：{}，手机号：{}", msg.getVin(), msg.getMobile());
            JSONObject json =  JSONUtil.parseObj(msg);
            mySmsService.sendSms(msg.getMobile(), msg.getTemplate(), json);
        };
    }



}
